<template>
  <div class="groupContainer">
    <el-row class="title">
      <el-col :span="24">
        <div class="orangeIcon" />
        <span class="spanStyle">管理范围</span>
        <el-tooltip
          class="item"
          effect="dark"
          :content="`用于确定该管理员组内管理员可管理授权的业务用户范围`"
          placement="top-start"
        >
          <i class="el-icon-question" />
        </el-tooltip>
        <div class="rangeDiv">
          <span>{{ range }}</span>
        </div>
      </el-col> </el-row><el-row v-if="!isEdit" class="main">
      <template v-if="selectData.length > 0">
        <el-col v-for="item in selectData" :key="item.orgId" :span="6">
          <svg-icon
            icon-class="groupAuth"
            style="width: 28px; height: 28px; vertical-align: baseline"
          />
          <div class="nameDiv">
            <span class="nameOne">{{ item.orgName }}</span>
            <span class="nameTwo">{{ item.orgFullPath }}</span>
          </div>
        </el-col>
      </template>
      <div v-else>
        <span class="nullSpan">同上级管理员组</span>
      </div>
    </el-row>
    <div v-else>
      <selectOrg
        v-model="datas"
        :select-data.sync="selectData"
        :column-props="columnProps"
      />
    </div>
    <el-divider />
  </div>
</template>

<script>
import adminManageApi from '@/framework/api/authCenter/adminManage/adminManage'
import selectOrg from '@/framework/components/addPerson/dt-select-org.vue'

export default {
  name: 'ManageScope',
  components: { selectOrg },
  props: {
    isEdit: {
      type: Boolean,
      default: false
    },
    groupId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      range: '',
      datas: '',
      columnProps: {
        groupId: this.groupId,
        relType: 1
      },
      selectData: []
    }
  },
  watch: {
    datas(newVal, oldVal) {
      this.$emit('input', newVal)
    }
  },
  mounted() {
    this.getDatas()
  },
  methods: {
    getDatas() {
      adminManageApi
        .getCurrentGroupDataScope({
          groupId: this.groupId,
          relType: 1
        })
        .then((resdata) => {
          this.selectData = resdata.data
          this.range =
            this.selectData?.length === 0 ? '同上级管理员组' : '指定范围'
          const orgs = this.selectData?.map((res) => res.orgId).join(',')
          this.datas = orgs
          this.$emit('input', orgs)
          this.$emit('getLoading', 1)
        })
    }
  }
}
</script>
<style scoped lang="scss">
.title {
  height: 24px;
  display: flex;
  align-items: center;
  margin-bottom: 16px;
  .spanStyle {
    font-size: 14px;
    font-weight: 400;
    color: #131414;
    line-height: 24px;
  }

  .orangeIcon {
    width: 3px;
    height: 12px;
    background: #ff8800;
    display: inline-block;
    margin-right: 6px;
    border-radius: 92px;
  }

  .item {
    width: 14px;
    height: 14px;
    color: var(--themeColor);
    margin-right: 16px;
  }

  .rangeDiv {
    height: 24px;
    background: #fcf6ec;
    border-radius: 4px;
    opacity: 1;
    border: 1px solid #f2d09d;
    display: inline-block;
    padding: 0 10px;
    line-height: 20px;

    span {
      height: 20px;
      font-size: 12px;
      font-family: HarmonyOS Sans SC-Regular, HarmonyOS Sans SC;
      font-weight: 400;
      color: #e6a23c;
    }
  }
}

.main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 25px;

  .nameDiv {
    margin-left: 8px;
    display: inline-block;

    .nameOne {
      font-size: 14px;
      font-weight: 400;
      color: #131414;
      line-height: 24px;
    }

    .nameTwo {
      display: block;
      font-size: 11px;
      font-weight: 400;
      color: #909399;
      line-height: 13px;
    }
  }

  .nullSpan {
    font-size: 14px;
    font-weight: 400;
    color: #606266;
    line-height: 24px;
  }
}
</style>
